package com.jiecao.news.jiecaonews.util.dao;


import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

import com.jiecao.news.jiecaonews.util.constants.Constants;


public class SQLiteHelper extends SQLiteOpenHelper {
	public static final String NEWS_LISTITEM_TB_NAME = "jiecao_news_listitem_tb";//新闻列表item
	public static final String NEWS_ARTICLE_TB_NAME = "jiecao_news_article_tb";//新闻内容
	public SQLiteHelper(Context context, String name, CursorFactory factory,
			int version) {
		super(context, name, factory, version);
	}
	
	public SQLiteHelper(Context context) {
		super(context, Constants.DB_NAME, null, Constants.DB_VERSION);
	}

	// 建表
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("CREATE TABLE IF NOT EXISTS " + NEWS_LISTITEM_TB_NAME + "(id integer,icon varchar(200),intro varchar(200),publish_time varchar(50),title varchar(100),is_readed integer,app_create_time varchar(50),share_num integer)");
		db.execSQL("CREATE TABLE IF NOT EXISTS " + NEWS_ARTICLE_TB_NAME + "(id integer,art_info text,app_create_time varchar(50))");
	}

	// 数据库版本变化时删除表再建立表
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		//考虑保留数据的问题
		db.execSQL("DROP TABLE IF EXISTS " + NEWS_LISTITEM_TB_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + NEWS_ARTICLE_TB_NAME);
		onCreate(db);
	}

}
